package com.tcxr.framework.base;

 
 

import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
 
import org.springframework.jdbc.core.JdbcTemplate;
 
 
 
public class DaoBase         {
	
	protected    final Logger logger = LoggerFactory.getLogger(getClass());
	 
	      @Autowired
		protected  JdbcTemplate jdbcTemplate;
	
	    protected static  HashMap<String,Integer> mapID=new HashMap<String, Integer>();

	    /**
	     * 通过表名字，和列 得到这个列的 最大的ID 并且 。加1
	     * mysql
	     * @return
	     */
	    protected   synchronized   Integer  getTableID(String pk,String table)
	    {
		Integer temp = mapID.get(table);
		if (temp == null) {
			 
			temp = jdbcTemplate.queryForInt("SELECT " + pk + " FROM " + table
					+ " ORDER BY  " + pk + " DESC LIMIT 0, 1");
			 mapID.put(table, temp);

		}
		temp++;
		mapID.put(table, temp);
		return temp;
	    }
	    
	  
	    
	    
	    //SELECT  th_id  FROM theme  ORDER BY  th_id DESC LIMIT 0, 1
	    
	    
	    
	    
	    
	    
	      
	      
	 

	    /**
	  	 * 表的当前行数
	  	 * @return
	  	 */
	  	public int getCount(Class c) {
	  		int count = jdbcTemplate.queryForInt("SELECT COUNT(*) FROM "+c.getSimpleName());
	  		return count;
	  	}
	
	  	/**
	  	 * 表的当前行数
	  	 * @return
	  	 */
	  	public int getCount(Class c,String whereSql) {
	  		int count = jdbcTemplate.queryForInt("SELECT COUNT(*) FROM "+c.getSimpleName()+whereSql);
	  		return count;
	  	}



	 
	
	
}
